********************************************************************************
* analyze_robust.do
* Purpose: Produce robustness tables for Appendix A.
*
* Contains all Appendix A robustness checks EXCEPT Tables A8, A9, A10
* (pre/post-matching balance tables, produced in descriptive_stats.do).
*
* Robustness checks covered include:
*   Table A1 : Alternative clustering (CZ x industry instead of firm level)
*   Table A2 : Alternative matching specifications (with ROA, with tenure)
*   Table A3 : Outcomes in Levels (Replacing Missing with Zeros)
*   Table A4 : By One-time vs. Repeat M&A (Acquirer)
*   Table A5 : Using Private Firms Only
*   Table A6 : Using Return on Assets as Additional Matching Variable
*   Table A7 : Using Tenure as Additional Matching Variable
*	Table A8 : Including Unmatched Eligible Firms and Workers
*   Figures A1-A8: Event-study plots supporting the robustness tables
*	Figure A10: decomposes the total log-earnings change into three channels:
*   (1) Employer Fixed Effect  -- change in AKM firm wage premium
*   (2) Match Effect           -- change in worker-employer match component
*   (3) Direct Effect          -- residual (total minus FE minus match)
*   (4) Total Earnings         -- event-study estimate of log(Earnings)
*
* Uses matched firm and worker panels from all matching variants.
*
* Input : $data/firm_matched.dta, $data/worker_matched.dta, and all variant
*         matched datasets (w_roa, diff_market, eligible, w_tenure, w_wage, etc.)
* Output: $out/tableA*.csv, $out/FigureA*.pdf
********************************************************************************
*        Appendix A      *
********************************************************************************
set more off

********************************************************************************
							* Table A1 * Target
********************************************************************************
use $data/firm_matched, replace

gen y_emp		 	= log(PD7_AvgEmp_NonZero)
gen y_avg_payroll 	= log(avg_payroll)

label var y_emp 			"log(Employment)"
label var y_avg_payroll 	"log(Average Payrolls)"

global FE				"id i.t##i.naics"
global clusters			"sac_syn naics"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A1 - Columns 1 and 2 - top row
gstats winsor y_*, replace cuts(5 95)  by(year)

* sample selection
keep if matched_deal_type == 0
keep if matched_acq == 0

local varlist "emp avg_payroll"
foreach v in `varlist'{
	eststo es0_`v': reghdfe y_`v' $ind_var age*, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m0_`v': lincomest $average_impact
	
	estimates restore es0_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es0_`v'
}

use $data/worker_matched, clear

*** Dependent Variables ***
gen y_t4earn 		= log(total_wage)
label var y_t4earn 	"log(Earnings)"

global FE 				"id i.t##i.naics"
global clusters 		"worker_id sac_syn naics"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A1 - Columns 3 - top row
gstats winsor y_*, replace cuts(5 95)  by(year)

keep if matched_acq == 0

local varlist "t4earn"
foreach v in `varlist'{
	eststo es0_`v': reghdfe y_`v' $ind_var, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m0_`v': lincomest $average_impact
	
	estimates restore es0_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'
	estimates store es0_`v'
}

#delimit ;
local title "f collabels(none) noobs title("") mtitle("log(Employment)" "log(Average Payrolls)" "log(Earnings)") coeflabel((1) "Target")";


esttab m0_* using $out/tableA1.csv,
replace `title'
starlevel(* 0.10 ** 0.05 *** 0.01) 
cells( b(star fmt(3)) se(par fmt(3)) ) type;

esttab es0_* using $out/tableA1.csv,
append plain f collabels(none) keep("") nomtitles 
stats(ym r2_a N, fmt(%9.2f %9.3f %9.0fc) label(
"Mean at t=-1"
"Adj. R squared" 
"Firm/Worker-Year Obs.")) type;

#delimit cr
********************************************************************************
							* Table A1 * Acquirer
********************************************************************************
use $data/firm_matched, replace

gen y_emp		 	= log(PD7_AvgEmp_NonZero)
gen y_avg_payroll 	= log(avg_payroll)

label var y_emp 			"log(Employment)"
label var y_avg_payroll 	"log(Average Payrolls)"

global FE				"id i.t##i.naics"
global clusters			"sac_syn naics"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A1 - Columns 1 and 2 - bottom row
gstats winsor y_*, replace cuts(5 95)  by(year)

* sample selection
keep if matched_deal_type == 0
keep if matched_acq == 1

local varlist "emp avg_payroll"
foreach v in `varlist'{
	eststo es1_`v': reghdfe y_`v' $ind_var age*, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m1_`v': lincomest $average_impact
	
	estimates restore es1_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es1_`v'
}
********************************************************************************
							* Table A1 * Acquirer
********************************************************************************
use $data/worker_matched, replace

*** Dependent Variables ***
gen y_t4earn 		= log(total_wage)
label var y_t4earn 			"log(Earnings)"

global FE 				"id i.t##i.naics"
global clusters 		"worker_id sac_syn naics"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A1 - Column 3 - bottom row
gstats winsor y_*, replace cuts(5 95)  by(year)

keep if matched_acq == 1

local varlist "t4earn"
foreach v in `varlist'{
	eststo es1_`v': reghdfe y_`v' $ind_var, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m1_`v': lincomest $average_impact
	
	estimates restore es1_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'
	estimates store es1_`v'
}

#delimit ;
local title "f collabels(none) noobs title("") nomtitles coeflabel((1) "Acquirer")";

esttab m1_* using $out/tableA1.csv,
append `title'
starlevel(* 0.10 ** 0.05 *** 0.01) 
cells( b(star fmt(3)) se(par fmt(3)) ) type;

esttab es1_* using $out/tableA1.csv,
append plain f collabels(none) keep("") nomtitles 
stats(ym r2_a N, fmt(%9.2f %9.3f %9.0fc) label(
"Mean at t=-1"
"Adj. R squared" 
"Firm/Worker-Year Obs.")) type;

#delimit cr

**# Figure A1 - A
#delimit ;
make_eventstudy emp,
	models("es1_emp es0_emp")
	colors("dknavy dkorange")
	labels("Acquirer Target")
	fmt("%9.1fc") ylab("-0.4(0.1)0.4")
	fig("FigureA1") subfig("A");

#delimit cr

**# Figure A1 - B
#delimit ;
make_eventstudy avg_payroll,
	models("es1_avg_payroll es0_avg_payroll")
	colors("dknavy dkorange")
	labels("Acquirer Target")
	fmt("%9.2fc") ylab("-0.1(0.05)0.1")
	fig("FigureA1") subfig("B");

#delimit cr

**# Figure A1 - C
#delimit ;
make_eventstudy t4earn,
	models("es1_t4earn es0_t4earn")
	colors("dknavy dkorange")
	labels("Acquirer Target")
	fmt("%9.2fc") ylab("-0.06(0.02)0.06")
	fig("FigureA1") subfig("C");

#delimit cr

#delimit ;
* To Take Out *;
global included_var2	"1.treated#1.ds_3 1.treated#1.ds_4 1.treated#1.ds_5 1.treated#1.ds_7 1.treated#1.ds_8 1.treated#1.ds_9 1.treated#1.ds_10 1.treated#1.ds_11 1.treated#1.ds_12";
forvalue h = 0/1{;
	esttab es`h'* using $out/FigureA1_C_`h'.csv, b se nostar noobs
	replace keep($included_var2);
};
#delimit cr

********************************************************************************
							* Table A2 * Target
********************************************************************************
use $data/firm_matched_diff_market, clear

gen y_emp		 	= log(PD7_AvgEmp_NonZero)
gen y_avg_payroll 	= log(avg_payroll)

label var y_emp 			"log(Employment)"
label var y_avg_payroll 	"log(Average Payrolls)"

global FE				"id i.t##i.naics"
global clusters			"firm_id"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A2 - Columns 1 and 2 - top row
gstats winsor y_*, replace cuts(5 95)  by(year)

* sample selection
keep if matched_deal_type == 0
keep if matched_acq == 0

local varlist "emp avg_payroll"
foreach v in `varlist'{
	eststo es0_`v': reghdfe y_`v' $ind_var age*, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es0_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es0_`v'
}

use $data/worker_matched_diff_market, clear

*** Dependent Variables ***
gen y_t4earn 		= log(total_wage)
label var y_t4earn 	"log(Earnings)"

global FE 				"id i.t##i.naics"
global clusters 		"worker_id firm_id"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A2 - Columns 3 - top row
gstats winsor y_*, replace cuts(5 95)  by(year)

keep if matched_acq == 0

local varlist "t4earn"
foreach v in `varlist'{
	eststo es0_`v': reghdfe y_`v' $ind_var, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es0_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es0_`v'
}

#delimit ;
local title "f collabels(none) noobs title("") mtitle("log(Employment)" "log(Average Payrolls)" "log(Earnings)") coeflabel((1) "Target")";


esttab m_* using $out/tableA2.csv,
replace `title'
starlevel(* 0.10 ** 0.05 *** 0.01) 
cells( b(star fmt(3)) se(par fmt(3)) ) type;

esttab es0_* using $out/tableA2.csv,
append plain f collabels(none) keep("") nomtitles 
stats(ym r2_a N, fmt(%9.2f %9.3f %9.0fc) label(
"Mean at t=-1"
"Adj. R squared" 
"Firm/Worker-Year Obs.")) type;

#delimit cr
********************************************************************************
							* Table A2 * Acquirer
********************************************************************************
use $data/firm_matched_diff_market, clear

gen y_emp		 	= log(PD7_AvgEmp_NonZero)
gen y_avg_payroll 	= log(avg_payroll)

label var y_emp 			"log(Employment)"
label var y_avg_payroll 	"log(Average Payrolls)"

global FE				"id i.t##i.naics"
global clusters			"firm_id"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A2 - Columns 1 and 2 - bottom row
gstats winsor y_*, replace cuts(5 95)  by(year)

* sample selection
keep if matched_deal_type == 0
keep if matched_acq == 1

local varlist "emp avg_payroll"
foreach v in `varlist'{
	eststo es1_`v': reghdfe y_`v' $ind_var age*, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es1_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es1_`v'
}

use $data/worker_matched_diff_market, clear

*** Dependent Variables ***
gen y_t4earn 		= log(total_wage)
label var y_t4earn 			"log(Earnings)"

global FE 				"id i.t##i.naics"
global clusters 		"worker_id firm_id"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A2 - Column 3 - bottom row
gstats winsor y_*, replace cuts(5 95)  by(year)

keep if matched_acq == 1

local varlist "t4earn"
foreach v in `varlist'{
	eststo es1_`v': reghdfe y_`v' $ind_var, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es1_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es1_`v'
}

#delimit ;
local title "f collabels(none) noobs title("") nomtitles coeflabel((1) "Acquirer")";

esttab m_* using $out/tableA2.csv,
append `title'
starlevel(* 0.10 ** 0.05 *** 0.01) 
cells( b(star fmt(3)) se(par fmt(3)) ) type;

esttab es1_* using $out/tableA2.csv,
append plain f collabels(none) keep("") nomtitles 
stats(ym r2_a N, fmt(%9.2f %9.3f %9.0fc) label(
"Mean at t=-1"
"Adj. R squared" 
"Firm/Worker-Year Obs.")) type;

#delimit cr

**# Figure A2 - A
#delimit ;
make_eventstudy emp,
	models("es1_emp es0_emp")
	colors("dknavy dkorange")
	labels("Acquirer Target")
	fmt("%9.1fc") ylab("-0.4(0.1)0.4")
	fig("FigureA2") subfig("A");

#delimit cr

**# Figure A2 - B
#delimit ;
make_eventstudy avg_payroll,
	models("es1_avg_payroll es0_avg_payroll")
	colors("dknavy dkorange")
	labels("Acquirer Target")
	fmt("%9.2fc") ylab("-0.1(0.05)0.1")
	fig("FigureA2") subfig("B");

#delimit cr

**# Figure A2 - C
#delimit ;
make_eventstudy t4earn,
	models("es1_t4earn es0_t4earn")
	colors("dknavy dkorange")
	labels("Acquirer Target")
	fmt("%9.2fc") ylab("-0.06(0.02)0.06")
	fig("FigureA2") subfig("C");

#delimit cr
estimates clear
********************************************************************************
							* Table A3 * Target
********************************************************************************
use $data/firm_matched_intermid, replace

gsort entid_syn year_prior year

gegen last_year_in_data = max(year), by(entid_syn)
gegen first_year_in_data= min(year), by(entid_syn)
gen exit_data =  year == last_year_in_data & last_year_in_data ~= 2017

** expand the data to add observations for missing years
gegen id	=	group(entid_syn year_prior)
fillin id year

gegen entid_syn_tmp			=	mode(entid_syn),			by(id)
gegen year_prior_tmp		=	mode(year_prior),			by(id)
gegen pairid_tmp			=	mode(pairid),				by(id)
gegen treated_tmp			=	mode(treated), 				by(id)
gegen last_year_tmp			=	mode(last_year_in_data), 	by(id)
gegen first_year_tmp		=	mode(first_year_in_data), 	by(id)

replace entid_syn			=	entid_syn_tmp
replace year_prior			=	year_prior_tmp
replace pairid				=	pairid_tmp
replace treated				=	treated_tmp
replace last_year_in_data	=	last_year_tmp
replace first_year_in_data	= 	first_year_tmp

drop if year < first_year_in_data

gegen 	firm_id     = group(entid_syn)

** sectors
destring naics, replace
gegen	naics_mode	=	mode(naics), by(entid_syn) minmode
replace naics		=	naics_mode	if mi(naics)
gen 	naics3 		= int(naics/10)
replace naics2  	= 31 if naics2 == 32 | naics2 == 33
replace naics2  	= 44 if naics2 == 45
replace naics2  	= 48 if naics2 == 49
replace naics2 		= 54 if naics2 == 56 | naics2 == 61 | naics2 ==62

gen 	t = year - (year_prior + 1)
replace t = 6 	if t >  5 	& ~mi(t)
replace t = -6 	if t < -5 	& ~mi(t)
tab t, gen(ds_)
levelsof t, local(ts)
local end = r(r)
forvalue i = 1(1)`end'{
	local temp = `i' - 7
	label variable ds_`i' "`temp'"
}
replace ds_6 = 0

* the sector prior to the event
gen 	naics2_event	= naics2 if treated == 1 & year == year_prior

* firm age - fill in for missing age values
drop 	dateinc dateinc_year age
gen 	temp_dateinc 	= dofc(BirthDate) if year == year_prior
gegen	dateinc 		= firstnm(temp_dateinc), by(id)
gen 	dateinc_year 	= yofd(dateinc)
gen 	age 			= year - dateinc_year
gen 	age2 			= age^2
gen 	age3 			= age^3
gen 	age4 			= age^4

replace Acquirer 	= . if ~(treated == 1 & year == year_prior)
replace merger 		= . if ~(treated == 1 & year == year_prior)

* pair-level variables
gsort pairid year_prior -treated year
gegen matched_acq 		= firstnm(Acquirer), 			by(pairid year_prior)
gegen matched_deal_type = firstnm(merger),				by(pairid year_prior)
gegen matched_sector 	= firstnm(naics2_event),		by(pairid year_prior)

** drop financial sectors **
drop if matched_sector == 52 | matched_sector == 55

gen y_emp		 	= PD7_AvgEmp_NonZero
replace y_emp		= 0 if _fillin == 1

gen y_avg_payroll 	= avg_payroll
replace y_avg_payroll = 0 if _fillin == 1

label var y_emp 			"Employment"
label var y_avg_payroll 	"Average Payrolls"

global FE				"id i.t##i.naics"
global clusters			"firm_id"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A3 - Columns 1 and 2 - top row
gstats winsor y_*, replace cuts(5 95)  by(year)

* sample selection
keep if matched_deal_type == 0
keep if matched_acq == 0

local varlist "emp avg_payroll"
foreach v in `varlist'{
	eststo es0_`v': reghdfe y_`v' $ind_var age*, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es0_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es0_`v'
}

use $data/worker_matched_intermid, replace

gsort pairid year_prior -treated year

gegen last_year_in_data = max(year), by(casenum2019)
gen  exit_data =  year == last_year_in_data & last_year_in_data ~= 2017

** expand the data to add observations for missing years
gegen id	=	group(casenum2019 year_prior)
fillin id year

gegen casenum2019_tmp		=	mode(casenum2019),			by(id)
gegen year_prior_tmp		=	mode(year_prior),			by(id)
gegen pairid_tmp			=	mode(pairid),				by(id)
gegen treated_tmp			=	mode(treated), 				by(id)
gegen last_year_tmp			=	mode(last_year_in_data), 	by(id)

replace casenum2019			=	casenum2019_tmp
replace year_prior			=	year_prior_tmp
replace pairid				=	pairid_tmp
replace treated				=	treated_tmp
replace last_year_in_data	=	last_year_tmp

gegen worker_id 	= group(casenum2019)
gegen 	firm_id 	= group(entid_syn)
replace firm_id 	= 0 	if mi(firm_id)

**# Time Variables
gen 	t = year - (year_prior + 1)
replace t = 6 	if t >  5 	& ~mi(t)
replace t = -6 	if t < -5 	& ~mi(t)
tab t, gen(ds_)
levelsof t, local(ts)
local end = r(r)
forvalue i = 1(1)`end'{
	local temp = `i' - 7
	label variable ds_`i' "`temp'"
}
replace ds_6 = 0

** sectors
destring naics, replace
drop naics2
gen 	naics2 = int(naics/100)
replace naics2 = 31 if naics2 == 32 | naics2 == 33
replace naics2 = 44 if naics2 == 45
replace naics2 = 48 if naics2 == 49
replace naics2 = 54 if naics2 == 56 | naics2 == 61 | naics2 ==62
replace naics  = 0 if _fillin == 1

** identify the sector prior to the event
gen naics2_event 	= naics2	if treated == 1	& year == year_prior
gen naics_event		= naics		if year == year_prior
gen firm_event 		= firm_id 	if year == year_prior
gegen naics_tmp 	= firstnm(naics_event), by(id)
gegen firmid_tmp 	= firstnm(firm_event),  by(id)
replace naics 		= naics_tmp if firm_id == firmid_tmp & year <= year_prior + 1

** merge in mna characteristics
merge	m:1 entid_syn 	using 	$data/first_mna, keep(1 3) keepusing(Acquirer) nogen
replace Acquirer = . 		if ~(t == -1 & treated == 1)

** create id-wide indicators
gsort pairid year_prior -treated year

gegen matched_acq           = firstnm(Acquirer), 			by(pairid year_prior)

*** Dependent Variables ***
gen 		y_t4earn 	= total_wage
gen 		y_total_wage = total_wage
replace 	y_t4earn	= 0 if _fillin == 1
label var	y_t4earn 	"Earnings"

global FE 				"id i.t##i.naics"
global clusters 		"worker_id firm_id"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A3 - Columns 3 - top row
gstats winsor y_*, replace cuts(5 95)  by(year)

keep if matched_acq == 0

local varlist "t4earn"
foreach v in `varlist'{
	eststo es0_`v': reghdfe y_`v' $ind_var, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es0_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es0_`v'
}

#delimit ;
local title "f collabels(none) noobs title("") mtitle("Employment" "Average Payrolls" "Earnings") coeflabel((1) "Target")";


esttab m_* using $out/tableA3.csv,
replace `title'
starlevel(* 0.10 ** 0.05 *** 0.01) 
cells( b(star fmt(3)) se(par fmt(3)) ) type;

esttab es0_* using $out/tableA3.csv,
append plain f collabels(none) keep("") nomtitles 
stats(ym r2_a N, fmt(%9.2f %9.3f %9.0fc) label(
"Mean at t=-1"
"Adj. R squared" 
"Firm/Worker-Year Obs.")) type;
#delimit cr

********************************************************************************
							* Table A3 * Acquirer
********************************************************************************
use $data/firm_matched_intermid, replace

gsort entid_syn year_prior year

gegen last_year_in_data = max(year), by(entid_syn)
gegen first_year_in_data= min(year), by(entid_syn)
gen exit_data =  year == last_year_in_data & last_year_in_data ~= 2017

** expand the data to add observations for missing years
gegen id	=	group(entid_syn year_prior)
fillin id year

gegen entid_syn_tmp			=	mode(entid_syn),			by(id)
gegen year_prior_tmp		=	mode(year_prior),			by(id)
gegen pairid_tmp			=	mode(pairid),				by(id)
gegen treated_tmp			=	mode(treated), 				by(id)
gegen last_year_tmp			=	mode(last_year_in_data), 	by(id)
gegen first_year_tmp		=	mode(first_year_in_data), 	by(id)

replace entid_syn			=	entid_syn_tmp
replace year_prior			=	year_prior_tmp
replace pairid				=	pairid_tmp
replace treated				=	treated_tmp
replace last_year_in_data	=	last_year_tmp
replace first_year_in_data	= 	first_year_tmp

drop if year < first_year_in_data

gegen 	firm_id     = group(entid_syn)

** sectors
destring naics, replace
gegen	naics_mode	=	mode(naics), by(entid_syn) minmode
replace naics		=	naics_mode	if mi(naics)
gen 	naics3 		= int(naics/10)
replace naics2  	= 31 if naics2 == 32 | naics2 == 33
replace naics2  	= 44 if naics2 == 45
replace naics2  	= 48 if naics2 == 49
replace naics2 		= 54 if naics2 == 56 | naics2 == 61 | naics2 ==62

gen 	t = year - (year_prior + 1)
replace t = 6 	if t >  5 	& ~mi(t)
replace t = -6 	if t < -5 	& ~mi(t)
tab t, gen(ds_)
levelsof t, local(ts)
local end = r(r)
forvalue i = 1(1)`end'{
	local temp = `i' - 7
	label variable ds_`i' "`temp'"
}
replace ds_6 = 0

* the sector prior to the event
gen 	naics2_event	= naics2 if treated == 1 & year == year_prior

* firm age - fill in for missing age values
drop 	dateinc dateinc_year age
gen 	temp_dateinc 	= dofc(BirthDate) if year == year_prior
gegen	dateinc 		= firstnm(temp_dateinc), by(id)
gen 	dateinc_year 	= yofd(dateinc)
gen 	age 			= year - dateinc_year
gen 	age2 			= age^2
gen 	age3 			= age^3
gen 	age4 			= age^4

replace Acquirer 	= . if ~(treated == 1 & year == year_prior)
replace merger 		= . if ~(treated == 1 & year == year_prior)

* pair-level variables
gsort pairid year_prior -treated year
gegen matched_acq 		= firstnm(Acquirer), 			by(pairid year_prior)
gegen matched_deal_type = firstnm(merger),				by(pairid year_prior)
gegen matched_sector 	= firstnm(naics2_event),		by(pairid year_prior)

** drop financial sectors **
drop if matched_sector == 52 | matched_sector == 55

**#  Dependent Variables
gen y_emp		 	= PD7_AvgEmp_NonZero
replace y_emp		= 0 if _fillin == 1

gen y_avg_payroll 	= avg_payroll
replace y_avg_payroll = 0 if _fillin == 1

label var y_emp 			"Employment"
label var y_avg_payroll 	"Average Payrolls"

global FE				"id i.t##i.naics"
global clusters			"firm_id"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A3 - Columns 1 and 2 - top row
gstats winsor y_*, replace cuts(5 95)  by(year)

* sample selection
keep if matched_deal_type == 0
keep if matched_acq == 1

local varlist "emp avg_payroll"
foreach v in `varlist'{
	eststo es1_`v': reghdfe y_`v' $ind_var age*, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es1_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es1_`v'
}

use $data/worker_matched_intermid, replace

gsort pairid year_prior -treated year

gegen last_year_in_data = max(year), by(casenum2019)
gen  exit_data =  year == last_year_in_data & last_year_in_data ~= 2017

** expand the data to add observations for missing years
gegen id	=	group(casenum2019 year_prior)
fillin id year

gegen casenum2019_tmp		=	mode(casenum2019),			by(id)
gegen year_prior_tmp		=	mode(year_prior),			by(id)
gegen pairid_tmp			=	mode(pairid),				by(id)
gegen treated_tmp			=	mode(treated), 				by(id)
gegen last_year_tmp			=	mode(last_year_in_data), 	by(id)

replace casenum2019			=	casenum2019_tmp
replace year_prior			=	year_prior_tmp
replace pairid				=	pairid_tmp
replace treated				=	treated_tmp
replace last_year_in_data	=	last_year_tmp

gegen worker_id 	= group(casenum2019)
gegen 	firm_id 	= group(entid_syn)
replace firm_id 	= 0 	if mi(firm_id)

gen 	t = year - (year_prior + 1)
replace t = 6 	if t >  5 	& ~mi(t)
replace t = -6 	if t < -5 	& ~mi(t)
tab t, gen(ds_)
levelsof t, local(ts)
local end = r(r)
forvalue i = 1(1)`end'{
	local temp = `i' - 7
	label variable ds_`i' "`temp'"
}
replace ds_6 = 0

** sectors
destring naics, replace
drop naics2
gen 	naics2 = int(naics/100)
replace naics2 = 31 if naics2 == 32 | naics2 == 33
replace naics2 = 44 if naics2 == 45
replace naics2 = 48 if naics2 == 49
replace naics2 = 54 if naics2 == 56 | naics2 == 61 | naics2 ==62
replace naics  = 0 if _fillin == 1

** identify the sector prior to the event
gen naics2_event 	= naics2	if treated == 1	& year == year_prior
gen naics_event		= naics		if year == year_prior
gen firm_event 		= firm_id 	if year == year_prior
gegen naics_tmp 	= firstnm(naics_event), by(id)
gegen firmid_tmp 	= firstnm(firm_event),  by(id)
replace naics 		= naics_tmp if firm_id == firmid_tmp & year <= year_prior + 1

** merge in mna characteristics
merge	m:1 entid_syn 	using 	$data/first_mna, keep(1 3) keepusing(Acquirer) nogen
replace Acquirer = . 		if ~(t == -1 & treated == 1)

** create id-wide indicators
gsort pairid year_prior -treated year

gegen matched_acq           = firstnm(Acquirer), 			by(pairid year_prior)

*** Dependent Variables ***
gen 		y_t4earn 	= total_wage
replace 	y_t4earn	= 0 if _fillin == 1
gen 		y_total_wage = total_wage
label var	y_t4earn 	"Earnings"

global FE 				"id i.t##i.naics"
global clusters 		"worker_id firm_id"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A3 - Columns 3 - top row
gstats winsor y_*, replace cuts(5 95)  by(year)

keep if matched_acq == 1

local varlist "t4earn"
foreach v in `varlist'{
	eststo es1_`v': reghdfe y_`v' $ind_var, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es1_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es1_`v'
}

#delimit ;
local title "f collabels(none) noobs title("") mtitle("Employment" "Average Payrolls" "Earnings") coeflabel((1) "Target")";


esttab m_* using $out/tableA3.csv,
append `title'
starlevel(* 0.10 ** 0.05 *** 0.01) 
cells( b(star fmt(3)) se(par fmt(3)) ) type;

esttab es1_* using $out/tableA3.csv,
append plain f collabels(none) keep("") nomtitles 
stats(ym r2_a N, fmt(%9.2f %9.3f %9.0fc) label(
"Mean at t=-1"
"Adj. R squared" 
"Firm/Worker-Year Obs.")) type;

#delimit cr

**# Figure A3 - A
#delimit ;
make_eventstudy emp,
	models("es1_emp es0_emp")
	colors("dknavy dkorange")
	labels("Acquirer Target")
	fmt("%9.0fc") ylab("-60(20)60")
	fig("FigureA3") subfig("A");

#delimit cr

**# Figure A3 - B
#delimit ;
make_eventstudy avg_payroll,
	models("es1_avg_payroll es0_avg_payroll")
	colors("dknavy dkorange")
	labels("Acquirer Target")
	fmt("%9.0fc") ylab("-20e3(5e3)53")
	fig("FigureA3") subfig("B");

#delimit cr

**# Figure A3 - C
#delimit ;
make_eventstudy t4earn,
	models("es1_t4earn es0_t4earn")
	colors("dknavy dkorange")
	labels("Acquirer Target")
	fmt("%9.0fc") ylab("-3e3(1.5e3)3e3")
	fig("FigureA3") subfig("C");

#delimit cr

#delimit cr

#delimit ;
* To Take Out *;
global included_var2	"1.treated#1.ds_3 1.treated#1.ds_4 1.treated#1.ds_5 1.treated#1.ds_7 1.treated#1.ds_8 1.treated#1.ds_9 1.treated#1.ds_10 1.treated#1.ds_11 1.treated#1.ds_12";
forvalue h = 0/1{;
	esttab es`h'* using $out/FigureA3_`h'.csv, b se nostar noobs
	replace keep($included_var2) type;
};
#delimit cr

*******************************
*        Table A4        *
*******************************
use $data/firm_matched, clear

* merge in the number of deals a firm was involved in
merge m:1 entid_syn	using $data/repeat_acquirer, keep(1 3) keepusing(num_deal) nogen

* number of deals throughout the sample at t = -1 for acquiring firms
gen 	repeat_tmp 		= num_deal > 1 & ~mi(num_deal) 
replace	repeat_tmp		= . if treated ~= 1 | t ~= -1

gegen 	matched_repeat	= firstnm(repeat_tmp),			by(pairid year_prior)

gen y_emp		 	= log(PD7_AvgEmp_NonZero)
gen y_avg_payroll 	= log(avg_payroll)

label var y_emp 			"log(Employment)"
label var y_avg_payroll 	"log(Average Payrolls)"

global FE				"id i.t##i.naics"
global clusters			"firm_id"

**# Table A4
gstats winsor y_*, replace cuts(5 95)  by(year)

keep if matched_deal_type == 0
keep if matched_acq == 1

estimates clear
local varlist "emp avg_payroll"
local hetero "matched_repeat"
foreach v in `varlist'{
	eststo es_`v': reghdfe y_`v' `hetero'##treated##ds_* age*, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo treated_`v': 	lincomest (1bn.treated#1bn.ds_7 + 1bn.treated#1bn.ds_8 + 1bn.treated#1bn.ds_9+1bn.treated#1bn.ds_10+1bn.treated#1bn.ds_11+1bn.treated#1bn.ds_12)/6
	
	estimates restore es_`v'
	eststo ddd_treated_`v': lincomest (1bn.`hetero'#1bn.treated#1bn.ds_7 + 1bn.`hetero'#1bn.treated#1bn.ds_8 + 1bn.`hetero'#1bn.treated#1bn.ds_9 + 1bn.`hetero'#1bn.treated#1bn.ds_10 + 1bn.`hetero'#1bn.treated#1bn.ds_11 + 1bn.`hetero'#1bn.treated#1bn.ds_12)/6
	
	estimates restore es_`v'
	summ `e(depvar)' if  treated == 1 & t == -1 & `hetero' == 0
	estadd scalar ym0 = `r(mean)', replace 
	summ `e(depvar)' if  `hetero' == 0
	estadd scalar n0 = `r(N)', replace 
	summ `e(depvar)' if  treated == 1 & t == -1 & `hetero' == 1
	estadd scalar ym1 = `r(mean)', replace 
	summ `e(depvar)' if  `hetero' == 1
	estadd scalar n1 = `r(N)', replace 
	estimates store es_`v'
}

#delimit ;
local first = 1;

if `first'{;
	local replace_append "replace";
	local title "f collabels(none) noobs title("") mtitle("log(Employment)" "log(Average Payrolls)") coeflabel((1) "Post X Treated")";
	local first = 0;
};

esttab treated_* using $out/tableA4.csv,
`replace_append' `title'
starlevel(* 0.10 ** 0.05 *** 0.01) 
cells( b(star fmt(3)) se(par fmt(3)) ) type;

esttab ddd_treated_* using $out/tableA4.csv,
append f collabels(none) noobs title("") nomtitles coeflabel((1) "Post X Treated X Repeat Acquirer")
starlevel(* 0.10 ** 0.05 *** 0.01) 
cells( b(star fmt(3)) se(par fmt(3)) ) type;

esttab es_* using $out/tableA4.csv,
append plain f collabels(none) keep("") nomtitles 
stats(ym0 ym1 r2_a n0 n1, fmt(%9.2f %9.2f %9.3f %9.0fc %9.0fc) label(
"Mean at t=-1 (One-Time Acquirer = 1)"
"Mean at t=-1 (Repeat Acquirer = 1)"
"Adj. R squared" 
"Worker-Year Obs. (One-Time Acquirer = 1))"
"Worker-Year Obs. (Repeat Acquirer = 1))")
) type;

#delimit cr

local varlist "emp avg_payroll"
local hetero "matched_repeat"
foreach v in `varlist'{
	
	eststo es0_`v': reghdfe y_`v' treated##ds_* if `hetero' == 0,  a($FE) vce( cluster $clusters ) tol(1e-6)
	estimate restore es0_`v'
	
	eststo es1_`v': reghdfe y_`v' treated##ds_* if `hetero' == 1,  a($FE) vce( cluster $clusters ) tol(1e-6)
	estimate restore es1_`v'
}

**# Figure A4 - A
#delimit ;
make_eventstudy emp,
	models("es0_emp es1_emp")
	colors("ltblue dknavy")
	labels("OneTime Repeat")
	fmt("%9.2fc") ylab("-0.4(0.2)0.6")
	fig("FigureA4") subfig("A");

#delimit cr

**# Figure A4 - B
#delimit ;
make_eventstudy avg_payroll,
	models("es0_avg_payroll es1_avg_payroll")
	colors("ltblue dknavy")
	labels("OneTime Repeat")
	fmt("%9.2fc") ylab("-0.1(0.05)0.1")
	fig("FigureA4") subfig("B");

#delimit cr

#delimit ;
* To Take Out *;
global included_var2	"1.treated#1.ds_3 1.treated#1.ds_4 1.treated#1.ds_5 1.treated#1.ds_7 1.treated#1.ds_8 1.treated#1.ds_9 1.treated#1.ds_10 1.treated#1.ds_11 1.treated#1.ds_12";
forvalue h = 0/1{;
	esttab es`h'* using $out/FigureA4_`h'.csv, b se nostar noobs
	replace keep($included_var2) type;
};
#delimit cr
estimates clear

********************************************************************************
							* Table A5 * Target
********************************************************************************
use $data/firm_matched, replace

** public v private indicator
merge	m:1		entid_syn			using $data/ipo_indicator, 		keep(1 3) keepusing(ipo_indicator) nogen
replace		ipo_indicator	= .		if treated ~= 1 | t ~= -1
replace		ipo_indicator	= 0		if treated == 1 & t == -1 & mi(ipo_indicator)
gegen 		matched_public	= firstnm(ipo_indicator),		by(pairid year_prior)


**#  Dependent Variables
gen y_emp		 	= log(PD7_AvgEmp_NonZero)
gen y_avg_payroll 	= log(avg_payroll)

label var y_emp 			"log(Employment)"
label var y_avg_payroll 	"log(Average Payrolls)"

global FE				"id i.t##i.naics"
global clusters			"firm_id"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A5 - Columns 1 and 2 - top row
gstats winsor y_*, replace cuts(5 95)  by(year)

* sample selection
keep if matched_deal_type == 0
keep if matched_public == 0
keep if matched_acq == 0

local varlist "emp avg_payroll"
foreach v in `varlist'{
	eststo es0_`v': reghdfe y_`v' $ind_var age*, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es0_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es0_`v'
}

use $data/worker_matched, replace

merge	m:1	entid_syn		using 	$data/ipo_indicator, 				keep(1 3) nogen
*** public vs. private
replace ipo_indicator 		= . if treated == 0 | t ~= -1
replace ipo_indicator 		= 0 if treated == 1 & t == -1 & mi(ipo_indicator)
gegen 	matched_public		= firstnm(ipo_indicator),	 			by(pairid year_prior)

*** Dependent Variables ***
gen y_t4earn 		= log(total_wage)
label var y_t4earn 	"log(Earnings)"


global FE 				"id i.t##i.naics"
global clusters 		"worker_id firm_id"

**# Table A5 - Columns 3 - bottom row
gstats winsor y_*, replace cuts(5 95)  by(year)

keep if matched_public == 0
keep if matched_acq == 0


local varlist "t4earn"
foreach v in `varlist'{
	eststo es0_`v': reghdfe y_`v' $ind_var, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es0_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)' 
	estimates store es0_`v'
}

#delimit ;
local title "f collabels(none) noobs title("") mtitle("log(Employment)" "log(Average Payrolls)" "log(Earnings)") coeflabel((1) "Target")";


esttab m_* using $out/tableA5.csv,
replace `title'
starlevel(* 0.10 ** 0.05 *** 0.01) 
cells( b(star fmt(3)) se(par fmt(3)) ) type;

esttab es0_* using $out/tableA5.csv,
append plain f collabels(none) keep("") nomtitles 
stats(ym r2_a N, fmt(%9.2f %9.3f %9.0fc) label(
"Mean at t=-1"
"Adj. R squared" 
"Firm/Worker-Year Obs.")) type;

#delimit cr
********************************************************************************
							* Table A5 * Acquirer
********************************************************************************
use $data/firm_matched, replace

** public v private indicator
merge	m:1		entid_syn			using $data/ipo_indicator, 		keep(1 3) keepusing(ipo_indicator) nogen
replace		ipo_indicator	= .		if treated ~= 1 | t ~= -1
replace		ipo_indicator	= 0		if treated == 1 & t == -1 & mi(ipo_indicator)
gegen 		matched_public	= firstnm(ipo_indicator),		by(pairid year_prior)

gen y_emp		 	= log(PD7_AvgEmp_NonZero)
gen y_avg_payroll 	= log(avg_payroll)

label var y_emp 			"log(Employment)"
label var y_avg_payroll 	"log(Average Payrolls)"

global FE				"id i.t##i.naics"
global clusters			"firm_id"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A5 - Columns 1 and 2 - bottom row
gstats winsor y_*, replace cuts(5 95)  by(year)

* sample selection
keep if matched_deal_type == 0
keep if matched_public == 0
keep if matched_acq == 1

local varlist "emp avg_payroll"
foreach v in `varlist'{
	eststo es1_`v': reghdfe y_`v' $ind_var age*, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es1_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es1_`v'
}

use $data/worker_matched, replace

merge	m:1	entid_syn		using 	$data/ipo_indicator, 				keep(1 3) nogen
*** public vs. private
replace ipo_indicator 		= . if treated == 0 | t ~= -1
replace ipo_indicator 		= 0 if treated == 1 & t == -1 & mi(ipo_indicator)
gegen 	matched_public		= firstnm(ipo_indicator),	 			by(pairid year_prior)

*** Dependent Variables ***
gen y_t4earn 		= log(total_wage)
label var y_t4earn 	"log(Earnings)"


global FE 				"id i.t##i.naics"
global clusters 		"worker_id firm_id"

**# Table A5 - Columns 3 - bottom row
gstats winsor y_*, replace cuts(5 95)  by(year)

* sample selection
keep if matched_public == 0
keep if matched_acq == 1


local varlist "t4earn"
foreach v in `varlist'{
	eststo es1_`v': reghdfe y_`v' $ind_var, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es1_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'
	estimates store es1_`v'
}

#delimit ;
local title "f collabels(none) noobs title("") nomtitles coeflabel((1) "Acquirer")";

esttab m_* using $out/tableA5.csv,
append `title'
starlevel(* 0.10 ** 0.05 *** 0.01) 
cells( b(star fmt(3)) se(par fmt(3)) ) type;

esttab es1_* using $out/tableA5.csv,
append plain f collabels(none) keep("") nomtitles 
stats(ym r2_a N, fmt(%9.2f %9.3f %9.0fc) label(
"Mean at t=-1"
"Adj. R squared" 
"Firm/Worker-Year Obs.")) type;

#delimit cr

**# Figure A5 - A
#delimit ;
make_eventstudy emp,
	models("es1_emp es0_emp")
	colors("dknavy dkorange")
	labels("Acquirer Target")
	fmt("%9.1fc") ylab("-0.4(0.1)0.4")
	fig("FigureA5") subfig("A");

#delimit cr

**# Figure A5 - B
#delimit ;
make_eventstudy avg_payroll,
	models("es1_avg_payroll es0_avg_payroll")
	colors("dknavy dkorange")
	labels("Acquirer Target")
	fmt("%9.2fc") ylab("-0.1(0.05)0.1")
	fig("FigureA5") subfig("B");

#delimit cr

**# Figure A5 - C
#delimit ;
make_eventstudy t4earn,
	models("es1_t4earn es0_t4earn")
	colors("dknavy dkorange")
	labels("Acquirer Target")
	fmt("%9.2fc") ylab("-0.06(0.02)0.06")
	fig("FigureA5") subfig("C");

#delimit cr

************************************************************************
							* Table A6 * Target
************************************************************************
use $data/firm_matched_w_roa, clear

*  Dependent Variables
gen y_emp		 	= log(PD7_AvgEmp_NonZero)
gen y_avg_payroll 	= log(avg_payroll)

label var y_emp 			"log(Employment)"
label var y_avg_payroll 	"log(Average Payrolls)"

global FE				"id i.t##i.naics"
global clusters			"firm_id"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A6 - Columns 1 and 2 - top row
gstats winsor y_*, replace cuts(5 95)  by(year)

* sample selection
keep if matched_deal_type == 0
keep if matched_acq == 0

local varlist "emp avg_payroll"
foreach v in `varlist'{
	eststo es0_`v': reghdfe y_`v' $ind_var age*, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es0_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es0_`v'
}

use $data/worker_matched_w_roa, clear

*** Dependent Variables ***
gen y_t4earn 		= log(total_wage)
label var y_t4earn 	"log(Earnings)"

global FE 				"id i.t##i.naics"
global clusters 		"worker_id firm_id"

**# Table A6 - Columns 3 - top row
gstats winsor y_*, replace cuts(5 95)  by(year)

keep if matched_acq == 0

local varlist "t4earn"
foreach v in `varlist'{
	eststo es0_`v': reghdfe y_`v' $ind_var, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es0_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es0_`v'
}

#delimit ;
local title "f collabels(none) noobs title("") mtitle("log(Employment)" "log(Average Payrolls)" "log(Earnings)") coeflabel((1) "Target")";


esttab m_* using $out/tableA6.csv,
replace `title'
starlevel(* 0.10 ** 0.05 *** 0.01) 
cells( b(star fmt(3)) se(par fmt(3)) ) type;

esttab es0_* using $out/tableA6.csv,
append plain f collabels(none) keep("") nomtitles 
stats(ym r2_a N, fmt(%9.2f %9.3f %9.0fc) label(
"Mean at t=-1"
"Adj. R squared" 
"Firm/Worker-Year Obs.")) type;

#delimit cr

********************************************************************************
							* Table A6 * Acquirer
********************************************************************************
use $data/firm_matched_w_roa, clear

gen y_emp		 	= log(PD7_AvgEmp_NonZero)
gen y_avg_payroll 	= log(avg_payroll)

label var y_emp 			"log(Employment)"
label var y_avg_payroll 	"log(Average Payrolls)"

global FE				"id i.t##i.naics"
global clusters			"firm_id"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A6 - Columns 1 and 2 - bottom row
gstats winsor y_*, replace cuts(5 95)  by(year)

* sample selection
keep if matched_deal_type == 0
keep if matched_acq == 1

local varlist "emp avg_payroll"
foreach v in `varlist'{
	eststo es1_`v': reghdfe y_`v' $ind_var age*, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es1_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es1_`v'
}

use $data/worker_matched_w_roa, clear

*** Dependent Variables ***
gen y_t4earn 		= log(total_wage)
label var y_t4earn 			"log(Earnings)"

*destring SAC_syn, gen(sac_syn)

global FE 				"id i.t##i.naics"
global clusters 		"worker_id firm_id"

**# Table A6 - Columns 3 - bottom row
gstats winsor y_*, replace cuts(5 95)  by(year)

* sample selection
keep if matched_acq == 1


local varlist "t4earn"
foreach v in `varlist'{
	eststo es1_`v': reghdfe y_`v' $ind_var, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es1_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)' 
	estimates store es1_`v'
}

#delimit ;
local title "f collabels(none) noobs title("") nomtitles coeflabel((1) "Acquirer")";

esttab m_* using $out/tableA6.csv,
append `title'
starlevel(* 0.10 ** 0.05 *** 0.01) 
cells( b(star fmt(3)) se(par fmt(3)) ) type;

esttab es1_* using $out/tableA6.csv,
append plain f collabels(none) keep("") nomtitles 
stats(ym r2_a N, fmt(%9.2f %9.3f %9.0fc) label(
"Mean at t=-1"
"Adj. R squared" 
"Firm/Worker-Year Obs.")) type;

#delimit cr

**# Figure A6 - A
#delimit ;
make_eventstudy emp,
	models("es1_emp es0_emp")
	colors("dknavy dkorange")
	labels("Acquirer Target")
	fmt("%9.1fc") ylab("-0.4(0.1)0.4")
	fig("FigureA6") subfig("A");

#delimit cr

**# Figure A6 - B
#delimit ;
make_eventstudy avg_payroll,
	models("es1_avg_payroll es0_avg_payroll")
	colors("dknavy dkorange")
	labels("Acquirer Target")
	fmt("%9.2fc") ylab("-0.1(0.05)0.1")
	fig("FigureA6") subfig("B");

#delimit cr

**# Figure A6 - C
#delimit ;
make_eventstudy t4earn,
	models("es1_t4earn es0_t4earn")
	colors("dknavy dkorange")
	labels("Acquirer Target")
	fmt("%9.2fc") ylab("-0.06(0.02)0.06")
	fig("FigureA6") subfig("C");

#delimit cr

#delimit ;
* To Take Out *;
global included_var2	"1.treated#1.ds_3 1.treated#1.ds_4 1.treated#1.ds_5 1.treated#1.ds_7 1.treated#1.ds_8 1.treated#1.ds_9 1.treated#1.ds_10 1.treated#1.ds_11 1.treated#1.ds_12";
forvalue h = 0/1{;
	esttab es`h'* using $out/FigureA6_`h'.csv, b se nostar noobs
	replace keep($included_var2) type;
};
#delimit cr

********************************************************************************
**# Table A7
********************************************************************************
use $data/worker_matched_w_tenure, clear

*** Dependent Variables ***
gen y_t4earn 		= log(total_wage)
gen y_moved			= moved

label var y_t4earn 			"log(Earnings)"
label var y_moved 			"Transition"

global FE 				"id i.t##i.naics"
global clusters 		"worker_id firm_id"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A7 - Column 1
preserve
gstats winsor y_*, replace cuts(5 95)  by(year)

keep if matched_acq == 1

estimates clear
local varlist "t4earn"
foreach v in `varlist'{
	eststo es0_`v': reghdfe y_`v' $ind_var, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m0_`v': lincomest $average_impact
	
	estimates restore es0_`v'
	summ `e(depvar)' if treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es0_`v'
}

**# Table A7 - Column 2
restore, preserve
gstats winsor y_*, replace cuts(5 95)  by(year)

keep if matched_acq == 1
keep if present_at_firm == 1

local varlist "t4earn"
foreach v in `varlist'{
	eststo es0_`v'_stay: reghdfe y_`v' $ind_var, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m0_`v'_stay: lincomest $average_impact
	
	estimates restore es0_`v'_stay
	summ `e(depvar)' if treated == 1 & t == -1
	estadd scalar ym = `r(mean)'
	estimates store es0_`v'_stay
}

**# Table A7 - Column 3
restore, preserve
gstats winsor y_*, replace cuts(5 95)  by(year)

keep if matched_acq == 0

local varlist "t4earn"
foreach v in `varlist'{
	eststo es1_`v': reghdfe y_`v' $ind_var, a($FE) vce( cluster $clusters ) tol(1e-6)
	
	eststo m1_`v': lincomest $average_impact
	
	estimates restore es1_`v'
	summ `e(depvar)' if treated == 1 & t == -1
	estadd scalar ym = `r(mean)'
  	estimates store es1_`v'
}

**# Table A7 - Column 4
restore, preserve
gstats winsor y_*, replace cuts(5 95)  by(year)

keep if matched_acq == 0
keep if present_at_firm == 1

local varlist "t4earn"
foreach v in `varlist'{
	eststo es1_`v'_stay: reghdfe y_`v' $ind_var, a($FE) vce( cluster $clusters ) tol(1e-6)
	
	eststo m1_`v'_stay: lincomest $average_impact
	
	estimates restore es1_`v'_stay
	summ `e(depvar)' if treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  	
	estimates store es1_`v'_stay
}

**# Table A7 - Column 5
restore, preserve
gstats winsor y_*, replace cuts(5 95)  by(year)

keep if matched_acq == 0

* first two cohort of movers
keep if matched_emoved == 1
replace t_moved = . if treated == 0
gegen min_t_moved = min(t_moved), by(pairid year_prior)
keep if min_t_moved == 1 | min_t_moved == 2

local varlist "t4earn"
foreach v in `varlist'{
	eststo es0_`v'_mover: reghdfe y_`v' $ind_var, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m0_`v'_mover: lincomest $average_impact
	
	estimates restore es0_`v'_mover
	summ `e(depvar)' if treated == 1 & t == -1
	estadd scalar ym = `r(mean)'
	estimates store es0_`v'_mover
}

#delimit ;
local first = 1;

if `first'{;
	local replace_append "replace";
	local title "f collabels(none) noobs title("") mtitle("Worker at Acquirer" "Acquirer Stayers" "Worker at Target" "Target Stayers" "Target Movers") coeflabel((1) "Workers at Target")";
	local first = 0;
};

esttab m* using "$out/tableA7.csv", 
`replace_append' `title'
starlevel(* 0.10 ** 0.05 *** 0.01) 
cells( b(star fmt(3)) se(par fmt(3)) ) type;

esttab es* using "$out/tableA7.csv", 
append plain f collabels(none) keep("") nomtitles 
stats(ym r2_a N, fmt(%9.2f %9.3f %9.0fc) label("Mean at t=-1" "Adj. R squared" "Firm-Year Obs.")) type;

#delimit cr

**# Figure A7 - A
#delimit ;
make_eventstudy t4earn,
	models("es1_t4earn es0_t4earn")
	colors("dknavy dkorange")
	labels("WorkeratAcquirer WorkeratTarget")
	fmt("%9.2fc") ylab("-0.06(0.02)0.06")
	fig("FigureA7") subfig("A");

#delimit cr

**# Figure A7 - B
#delimit ;
make_eventstudy t4earn_stay,
	models("es1_t4earn_stay es0_t4earn_stay")
	colors("dknavy dkorange")
	labels("WorkeratAcquirer WorkeratTarget")
	fmt("%9.2fc") ylab("-0.06(0.02)0.06")
	fig("FigureA7") subfig("B");

#delimit cr

**# Figure A7 - C
#delimit ;
make_eventstudy t4earn,
	models("es0_t4earn_mover")
	colors("dkorange")
	labels("WorkeratTarget")
	fmt("%9.2fc") ylab("-0.06(0.02)0.06")
	fig("FigureA7") subfig("C");

#delimit cr

#delimit ;
* To Take Out *;
global included_var2	"1.treated#1.ds_3 1.treated#1.ds_4 1.treated#1.ds_5 1.treated#1.ds_7 1.treated#1.ds_8 1.treated#1.ds_9 1.treated#1.ds_10 1.treated#1.ds_11 1.treated#1.ds_12";
forvalue h = 0/0{;
	esttab es* using $out/FigureA7.csv, b se nostar noobs
	replace keep($included_var2) type;
};
#delimit cr
estimates clear
********************************************************************************
**# Table A8
********************************************************************************
use $data/firm_eligible, replace

gen y_emp		 	= log(PD7_AvgEmp_NonZero)
gen y_avg_payroll 	= log(avg_payroll)

label var y_emp 			"log(Employment)"
label var y_avg_payroll 	"log(Average Payrolls)"

global FE				"id i.t##i.naics"
global clusters			"sac_syn naics"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A8 - Columns 1 and 2 - top row
gstats winsor y_*, replace cuts(5 95)  by(year)

* sample selection
keep if matched_deal_type == 0
keep if matched_acq == 0

local varlist "emp avg_payroll"
foreach v in `varlist'{
	eststo es0_`v': reghdfe y_`v' $ind_var age*, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es0_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es0_`v'
}

use $data/worker_eligible, clear

*** Dependent Variables ***
gen y_t4earn 		= log(total_wage)
label var y_t4earn 	"log(Earnings)"

global FE 				"id i.t##i.naics"
global clusters 		"worker_id sac_syn naics"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A8 - Columns 3 - top row
gstats winsor y_*, replace cuts(5 95)  by(year)

drop if treated == 0 & matched == 0
keep if matched_acq == 0

local varlist "t4earn"
foreach v in `varlist'{
	eststo es0_`v': reghdfe y_`v' $ind_var, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es0_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'
	estimates store es0_`v'
}

#delimit ;
local title "f collabels(none) noobs title("") mtitle("log(Employment)" "log(Average Payrolls)" "log(Earnings)") coeflabel((1) "Target")";


esttab m_* using $out/tableA8.csv,
replace `title'
starlevel(* 0.10 ** 0.05 *** 0.01) 
cells( b(star fmt(3)) se(par fmt(3)) ) type;

esttab es0_* using $out/tableA8.csv,
append plain f collabels(none) keep("") nomtitles 
stats(ym r2_a N, fmt(%9.2f %9.3f %9.0fc) label(
"Mean at t=-1"
"Adj. R squared" 
"Firm/Worker-Year Obs.")) type;

#delimit cr
********************************************************************************
							* Table A8 * Acquirer
********************************************************************************
use $data/firm_eligible, replace

gen y_emp		 	= log(PD7_AvgEmp_NonZero)
gen y_avg_payroll 	= log(avg_payroll)

label var y_emp 			"log(Employment)"
label var y_avg_payroll 	"log(Average Payrolls)"

global FE				"id i.t##i.naics"
global clusters			"sac_syn naics"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A8 - Columns 1 and 2 - bottom row
gstats winsor y_*, replace cuts(5 95)  by(year)

* sample selection
keep if matched_deal_type == 0
keep if matched_acq == 1

local varlist "emp avg_payroll"
foreach v in `varlist'{
	eststo es1_`v': reghdfe y_`v' $ind_var age*, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es1_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es1_`v'
}

use $data/worker_eligible, replace

*** Dependent Variables ***
gen y_t4earn 		= log(total_wage)
label var y_t4earn 			"log(Earnings)"

global FE 				"id i.t##i.naics"
global clusters 		"worker_id sac_syn naics"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A8 - Column 3 - bottom row
gstats winsor y_*, replace cuts(5 95)  by(year)

drop if treated == 0 & matched == 0
keep if matched_acq == 1

local varlist "t4earn"
foreach v in `varlist'{
	eststo es1_`v': reghdfe y_`v' $ind_var, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es1_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'
	estimates store es1_`v'
}

#delimit ;
local title "f collabels(none) noobs title("") nomtitles coeflabel((1) "Acquirer")";

esttab m_* using $out/tableA8.csv,
append `title'
starlevel(* 0.10 ** 0.05 *** 0.01) 
cells( b(star fmt(3)) se(par fmt(3)) ) type;

esttab es1_* using $out/tableA8.csv,
append plain f collabels(none) keep("") nomtitles 
stats(ym r2_a N, fmt(%9.2f %9.3f %9.0fc) label(
"Mean at t=-1"
"Adj. R squared" 
"Firm/Worker-Year Obs.")) type;

#delimit cr

**# Figure A8 - A
#delimit ;
make_eventstudy emp,
	models("es1_emp es0_emp")
	colors("dknavy dkorange")
	labels("Acquirer Target")
	fmt("%9.1fc") ylab("-0.4(0.1)0.4")
	fig("FigureA8") subfig("A");

#delimit cr

**# Figure A8 - B
#delimit ;
make_eventstudy avg_payroll,
	models("es1_avg_payroll es0_avg_payroll")
	colors("dknavy dkorange")
	labels("Acquirer Target")
	fmt("%9.2fc") ylab("-0.1(0.05)0.1")
	fig("FigureA8") subfig("B");

#delimit cr

**# Figure A8 - C
#delimit ;
make_eventstudy t4earn,
	models("es1_t4earn es0_t4earn")
	colors("dknavy dkorange")
	labels("Acquirer Target")
	fmt("%9.2fc") ylab("-0.06(0.02)0.06")
	fig("FigureA8") subfig("C");

#delimit cr

#delimit ;
* To Take Out *;
global included_var2	"1.treated#1.ds_3 1.treated#1.ds_4 1.treated#1.ds_5 1.treated#1.ds_7 1.treated#1.ds_8 1.treated#1.ds_9 1.treated#1.ds_10 1.treated#1.ds_11 1.treated#1.ds_12";
forvalue h = 0/1{;
	esttab es`h'* using $out/FigureA8_`h'.csv, b se nostar noobs
	replace keep($included_var2);
};
#delimit cr
estimates clear

********************************************************************************
*                         Figure A10 Analysis                                  *
********************************************************************************
use $data/worker_matched, clear

*** Dependent Variables ***
gen y_t4earn = log(total_wage)
gen y_fe     = fe
gen y_met    = logearnings_met

label var y_t4earn "log(Earnings)"
label var y_fe     "Employer Fixed Effect"
label var y_met    "Match Effect"

global FE       "id i.t##i.naics"
global clusters "worker_id firm_id"
global ind_var  "treated##ds_*"

*** Winsorize all outcomes jointly ***
gstats winsor y_*, replace cuts(5 95) by(year)

*** Sample: movers from targets, first two mover cohorts (same as Table 5) ***
keep if matched_acq == 0
keep if matched_emoved == 1
replace t_moved = . if treated == 0
gegen min_t_moved = min(t_moved), by(pairid year_prior)
keep if min_t_moved == 1 | min_t_moved == 2

**# Figure A10 - A: Wage decomposition event study
estimates clear

eststo es_t4earn: reghdfe y_t4earn $ind_var, a($FE) vce(cluster $clusters) tol(1e-6)
eststo es_fe:     reghdfe y_fe     $ind_var, a($FE) vce(cluster $clusters) tol(1e-6)
eststo es_met:    reghdfe y_met    $ind_var, a($FE) vce(cluster $clusters) tol(1e-6)

#delimit ;
make_eventstudy_decomp t4earn,
    mtotal("es_t4earn")
    mfe("es_fe")
    mmet("es_met")
    fmt("%9.2fc") ylab("-0.2(0.05)0.10")
    fig("FigureA10");
#delimit cr

********************************************************************************
							* Table A11 *
********************************************************************************
use $data/worker_matched_intermid, replace

gsort pairid year_prior -treated year

gegen last_year_in_data = max(year), by(casenum2019)
gen  exit_data =  year == last_year_in_data & last_year_in_data ~= 2017

** expand the data to add observations for missing years
gegen id	=	group(casenum2019 year_prior)
fillin id year

gegen casenum2019_tmp		=	mode(casenum2019),			by(id)
gegen year_prior_tmp		=	mode(year_prior),			by(id)
gegen pairid_tmp			=	mode(pairid),				by(id)
gegen treated_tmp			=	mode(treated), 				by(id)
gegen last_year_tmp			=	mode(last_year_in_data), 	by(id)

replace casenum2019			=	casenum2019_tmp
replace year_prior			=	year_prior_tmp
replace pairid				=	pairid_tmp
replace treated				=	treated_tmp
replace last_year_in_data	=	last_year_tmp

gegen worker_id 	= group(casenum2019)
gegen 	firm_id 	= group(entid_syn)
replace firm_id 	= 0 	if mi(firm_id)

**# Time Variables
gen 	t = year - (year_prior + 1)
replace t = 6 	if t >  5 	& ~mi(t)
replace t = -6 	if t < -5 	& ~mi(t)
tab t, gen(ds_)
levelsof t, local(ts)
local end = r(r)
forvalue i = 1(1)`end'{
	local temp = `i' - 7
	label variable ds_`i' "`temp'"
}
replace ds_6 = 0

** sectors
destring naics, replace
drop naics2
gen 	naics2 = int(naics/100)
replace naics2 = 31 if naics2 == 32 | naics2 == 33
replace naics2 = 44 if naics2 == 45
replace naics2 = 48 if naics2 == 49
replace naics2 = 54 if naics2 == 56 | naics2 == 61 | naics2 ==62
replace naics  = 0 if _fillin == 1

** identify the sector prior to the event
gen naics2_event 	= naics2	if treated == 1	& year == year_prior
gen naics_event		= naics		if year == year_prior
gen firm_event 		= firm_id 	if year == year_prior
gegen naics_tmp 	= firstnm(naics_event), by(id)
gegen firmid_tmp 	= firstnm(firm_event),  by(id)
replace naics 		= naics_tmp if firm_id == firmid_tmp & year <= year_prior + 1

** merge in mna characteristics
merge	m:1 entid_syn 	using 	$data/first_mna, keep(1 3) keepusing(Acquirer) nogen
replace Acquirer = . 		if ~(t == -1 & treated == 1)

** create id-wide indicators
gsort pairid year_prior -treated year

gegen matched_acq           = firstnm(Acquirer), 			by(pairid year_prior)

*** Dependent Variables ***
gsort id year

** Moved
by id: 	gen year_diff	= year - year[_n-1] & ~mi(entid_syn)
by id: 	gen moved 		= (firm_id ~= firm_id[_n-1] | year_diff >= 2) & ~mi(year_diff)

gen y_unemployed =	firm_id == 0 | (t1_uiearn > 0 & ~mi(t1_uiearn) & moved == 1)
label var	y_unemployed 	"Unemployed"

global FE 				"id i.t##i.naics"
global clusters 		"worker_id firm_id"
global ind_var 			"treated##ds_*"
global average_impact 	"(1.treated#1.ds_7 + 1.treated#1.ds_8 + 1.treated#1.ds_9 + 1.treated#1.ds_10 + 1.treated#1.ds_11 + 1.treated#1.ds_12)/6"

**# Table A11
gstats winsor y_*, replace cuts(5 95)  by(year)

keep if matched_acq == 0

local varlist "unemployed"
foreach v in `varlist'{
	eststo es0_`v': reghdfe y_`v' $ind_var, a($FE) vce( cluster $clusters ) tol(1e-6)

	eststo m_`v': lincomest $average_impact
	
	estimates restore es0_`v'
	summ `e(depvar)' if  treated == 1 & t == -1
	estadd scalar ym = `r(mean)'  
	estimates store es0_`v'
}

#delimit ;
local title "f collabels(none) noobs title("") mtitle("Employment" "Average Payrolls" "Earnings") coeflabel((1) "Target")";


esttab m_* using $out/tableA11_B.csv,
replace `title'
starlevel(* 0.10 ** 0.05 *** 0.01) 
cells( b(star fmt(3)) se(par fmt(3)) ) type;

esttab es0_* using $out/tableA11_B.csv,
append plain f collabels(none) keep("") nomtitles 
stats(ym r2_a N, fmt(%9.2f %9.3f %9.0fc) label(
"Mean at t=-1"
"Adj. R squared" 
"Firm/Worker-Year Obs.")) type;
#delimit cr

**# Figure A11 - B
#delimit ;
make_eventstudy unemployed,
	models("es0_unemployed")
	colors("dkorange")
	labels("WorkeratTarget")
	fmt("%9.2fc") ylab("-0.1(0.1)0.3")
	fig("FigureA11") subfig("B");

#delimit cr
